import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { TypeOrmModule } from '@nestjs/typeorm';
import jwtConfig from 'config/jwt.config';
import { User } from '../user/entities/user.entity';
import { HashingService } from './hashing.service';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { AccessTokenGuard } from 'src/common/guards/access-token.guard';
import { UnauthorizedExceptionFilter } from 'src/common/filters/unauthorized-exception.filter';

@Module({
  imports: [
    TypeOrmModule.forFeature([User]),
    ConfigModule.forFeature(jwtConfig),
    JwtModule.registerAsync(jwtConfig.asProvider()),
  ],
  controllers: [AuthController],
  providers: [
    HashingService,
    AuthService,
    {
      provide: 'APP_GUARD',
      useClass: AccessTokenGuard,
    },
    {
      provide: 'APP_FILTER',
      useClass: UnauthorizedExceptionFilter,
    },
  ],
})
export class AuthModule {}
